#pragma once
#include <codec.h>


class video_decoder : public ICodec
{
private:
    /* data */
      
public:
    video_decoder(/* args */const char* codec_name,AVCodecParameters* codecpar,AVRational timebase);
    ~video_decoder();
    int  decode(AVPacket* pkt,AVFrame* frame,int eof,int& got,int* finished) override;
    int  encode(const AVFrame*  frame, AVPacket* packet,int& got,int* finished) override;
    AVMediaType get_codec_type() const override;

private:
    AVDictionary *m_opts_dec = NULL;
    AVCodec *m_dec = nullptr;
    AVCodecContext  *m_dec_ctx = nullptr;
    std::string m_codec_name;
    bool m_open_success = false;
    int64_t m_frame_dec_in_cnt = 0;
    int64_t m_frame_dec_cnt  = 0;
    bool m_download_data_from_device = true;
    AVRational m_timebase;
private:
    int init_filters(const char *filters_spec);
private:
    AVFilterInOut   *m_filter_inputs;
    AVFilterInOut   *m_filter_outputs;
    AVFilterGraph   *m_filter_graph;
    AVFilterContext *m_buffersink_ctx;
    AVFilterContext *m_buffersrc_ctx;
    bool m_had_read_idr = false;    
    bool m_init_filters = false;
};


